package com.yonyou.cyxdms.sysAuth.service.controller;

import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyxdms.sysAuth.service.dto.SystemParamDTO;
import com.yonyou.cyxdms.sysAuth.service.entity.SystemParamPO;
import com.yonyou.cyxdms.sysAuth.service.service.SystemParamService;
import com.yonyou.cyxdms.sysAuth.service.vo.rule.AdviceVO;
import com.yonyou.cyxdms.sysmanage.client.vo.advice.AdviceRuleVO;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author ：quankk
 * @date ：2019/7/9 12:07
 * @description：获取常规数据
 */
@Api(value = "获取常规数据Controller", tags = {"获取常规数据Controller"})
@RestController
@RequestMapping("/commonDatas")
public class CommonDataController extends BaseController {

    // 定义日志接口
    private static final Logger logger = LoggerFactory.getLogger(CommonDataController.class);

    @Autowired
    private SystemParamService systemParamService;

    /**
     * @author ：quankk
     * @date ：2019/7/9 15:48
     * @description：获得常规数据(包括登陆信息等）
     */
    @RequestMapping(method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = " 获得常规数据(包括登陆信息等）")
    @ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
    public Map<String, Object> getCommonData() {
        return systemParamService.getCommonData();
    }

    @ApiOperation(value = "查询系统参数列表", notes = "查询系统参数列表", httpMethod = "GET")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @GetMapping(value = "/querySystemParaList")
    public List<SystemParamPO> querySystemParaList() {
        return systemParamService.querySystemParaList();
    }

    @ApiOperation(value = "修改系统参数", notes = "修改系统参数", httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({@ApiResponse(code = 200, message = "保存成功")})
    @PostMapping(value = "/modifySystemPara", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void updateSystemPara(@RequestBody List<SystemParamDTO> systemParamDTO) {
        systemParamService.updateSystemPara(systemParamDTO);
    }

    /**
     * 获取指定经销商配置的策略信息
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/8/15
     */
    @ApiOperation(value = "获取经销商策略", notes = "获取经销商策略", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping("/ownerRatio")
    public String getRatioByownerCode(@RequestParam("companyId") Long companyId) {
        return systemParamService.getRatioByownerCode(companyId);
    }

    /**
     * 通知规则设定
     *
     * @param:
     * @return:
     * @auther: 李贺
     * @since: 2019/9/16
     */
    @ApiOperation(value = "通知规则设定", notes = "通知规则设定")
    @ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
    @PostMapping("/adviceRule")
    public void setAdviceRule(@RequestBody List<AdviceVO> adviceRule) {
        systemParamService.setAdviceRules(adviceRule);
    }

    /**
     * 获取通知规则
     *
     * @auther: 李贺
     * @since: 2019/9/16
     */
    @ApiOperation(value = "获取通知规则", notes = "获取通知规则")
    @ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
    @PostMapping("/getAdviceRule")
    public List<AdviceVO> findAdviceRule(@RequestBody List<String> paramCodes) {
        return systemParamService.getAdviceRule(paramCodes);
    }

    /**
     * 供定时器使用
     *
     * @auther: 李贺
     * @since: 2019/9/18
     */
    @ApiOperation(value = "获取通知定时器设置", notes = "获取通知定时器设置")
    @GetMapping("/adviceRules")
    public List<AdviceRuleVO> findAdviceRules(@ApiParam(name = "paramCode", value = "paramCode", required = true) @RequestParam String paramCode) {
        return systemParamService.getAdviceRules(paramCode);
    }
}
